package com.example.news.controller;


import annotation.RequireRoles;
import com.example.news.service.NewscategoryServiceImpl;
import entity.PageParam;
import entity.Rsp;
import entity.Newscategory;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 模块接口
 */

@RestController
@Api(value = " 模块接口",description=" 模块接口")
public class NewscategoryController {

    private static final Logger log = LoggerFactory.getLogger(NewscategoryController.class);

    @Autowired
    NewscategoryServiceImpl newscategoryService;



    @PostMapping("/searchSomeNewscategoryByPage")
    @RequireRoles(roles = {"admin","super_admin","news_admin","news_editor"},index = 2)
    @ApiOperation("查询所有 支持 多条件 分页 排序 查询")
    public Rsp searchSomeByPage(@RequestBody PageParam<Newscategory> newscategoryPageParam,
                                @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){

        log.info("userId:{}",userId);
        log.info("roleId:{}",roleSign);

        return Rsp.success(newscategoryService.searchSomeByPage(newscategoryPageParam));
    }


    @RequireRoles(roles = {"super_admin","admin","news_admin"},index = 2)
    @PostMapping("/addOneNewscategory")
    @ApiOperation("添加单个")
    public Rsp addOne(@RequestBody @Valid Newscategory newscategory, @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){

        newscategory.setCreateUserId(userId);
        return newscategoryService.addOne(newscategory);
    }


    @RequireRoles(roles = {"super_admin","news_admin"},index = 2)
    @PostMapping("/deleteOneNewscategoryTrue")
    @ApiOperation("通过ID物理删除")
    public Rsp deleteOneNewscategoryTrue(@RequestBody Newscategory newscategory, @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){

        return newscategoryService.deleteOneTrue(newscategory.getId());
    }

    @RequireRoles(roles = {"super_admin","admin","news_admin","news_editor"},index = 2)
    @PostMapping("/updateNewscategory")
    @ApiOperation("动态修改")
    public Rsp updateNewscategory(@RequestBody Newscategory newscategory, @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){


		newscategory.setUpdateUserId(userId);
        return newscategoryService.update(newscategory);
    }

    @RequireRoles(roles = {"super_admin","news_admin","news_editor"},index = 2)
    @PostMapping("/deleteNewscategoryLogical")
    @ApiOperation("通过ID逻辑删除")
    public Rsp deleteNewscategoryLogical(@RequestBody Newscategory newscategory, @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){



        return newscategoryService.deleteLogical(newscategory);
    }

    @RequireRoles(roles = {"super_admin","news_admin","news_editor"},index = 2)
    @PostMapping("/recoverNewscategoryLogical")
    @ApiOperation("逻辑恢复")
    public Rsp recoverNewscategoryLogical(@RequestBody Newscategory newscategory, @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){



        return newscategoryService.recoverLogical(newscategory);
    }


    @RequireRoles(roles = {"super_admin","news_admin"},index = 2)
    @PostMapping("/deleteBatchNewscategoryTrue")
    @ApiOperation("批量物理删除")
    public Rsp deleteBatchNewscategoryTrue(@RequestBody List<String> ids, @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){



        return newscategoryService.deleteBatchTrue(ids);
    }

    @RequireRoles(roles = {"super_admin","news_admin"},index = 2)
    @PostMapping("/deleteBatchNewscategoryLogical")
    @ApiOperation("批量逻辑删除")
    public Rsp deleteBatchNewscategoryLogical(@RequestBody List<String> ids, @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){



        return newscategoryService.deleteBatchLogical(ids);
    }

    @RequireRoles(roles = {"super_admin","news_admin"},index = 2)
    @PostMapping("/deleteSomeNewscategoryLogicalByCondition")
    @ApiOperation("条件逻辑删除")
    public Rsp deleteSomeNewscategoryLogicalByCondition(@RequestBody Newscategory newscategory, @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){



        return newscategoryService.deleteSomeLogicalByCondition(newscategory);
    }

    @RequireRoles(roles = {"super_admin","news_admin"},index = 2)
    @PostMapping("/deleteSomeNewscategoryTrueByCondition")
    @ApiOperation("条件物理删除")
    public Rsp deleteSomeNewscategoryTrueByCondition(@RequestBody Newscategory newscategory, @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){



        return newscategoryService.deleteSomeTrueByCondition(newscategory);
    }


}
